#include "StdAfx.h"
#include "DllFunInfo.h"
#include "APITypeDef.h"

CHAR CDllFunInfo::m_StrFunName[FunNum][MAXPNAMELEN]={0};
CHAR CDllFunInfo::m_StrFunDllName[FunNum][MAXPNAMELEN]={0};
PVOID CDllFunInfo::m_HookFunAddr[FunNum]={0};

PVOID CDllFunInfo::GetHookFunAddress( FunNameID fn )
{
	PVOID retval=NULL;
	if (fn<FunNum)
	{
		retval=m_HookFunAddr[fn];
	}
	return retval;
}

LPCSTR CDllFunInfo::GetFunDllName( FunNameID fn )
{
	LPCSTR retval=NULL;
	if (fn<FunNum)
	{
		retval=&m_StrFunDllName[fn][0];
	}
	return retval;
}

LPCSTR CDllFunInfo::GetFunStrName( FunNameID fn )
{
	LPCSTR retval=NULL;
	if (fn<FunNum)
	{
		retval=&m_StrFunName[fn][0];
	}
	return retval;
}

void CDllFunInfo::InitFunAddr( void )
{
	SetFunInfo(eMessageBoxW,HOOKMessageBoxW,"user32.dll","MessageBoxW");//for test
	SetFunInfo(esendto,HOOKsendto,"Ws2_32.dll","sendto");
	SetFunInfo(esend,HOOKsend,"Ws2_32.dll","send");
	SetFunInfo(elisten,HOOKlisten,"Ws2_32.dll","listen");
	SetFunInfo(ebind,HOOKbind,"Ws2_32.dll","bind");
	SetFunInfo(econnect,HOOKconnect,"Ws2_32.dll","connect");
	SetFunInfo(erecv,HOOKrecv,"Ws2_32.dll","recv");
	SetFunInfo(erecvfrom,HOOKrecvfrom,"Ws2_32.dll","recvfrom");
}

inline void CDllFunInfo::SetFunInfo( FunNameID fn,PVOID HookFunAddr,LPCSTR strDllName,LPCSTR strFunName )
{
	if (fn<FunNum)
	{
		m_HookFunAddr[fn]=HookFunAddr;
		strcpy_s(&m_StrFunDllName[fn][0],MAXPNAMELEN,strDllName);
		strcpy_s(&m_StrFunName[fn][0],MAXPNAMELEN,strFunName);
	}
}